package com.xb.p25_intentservice;

import android.app.IntentService;
import android.content.Intent;
import android.util.Log;

public class MyIntentService extends IntentService {

    public MyIntentService() {
        super("MyIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        if (intent != null) {
            String num = (String) intent.getExtras().get("number");
            if("1".equals(num)){
                Log.i("test","当前线程："+Thread.currentThread().getName()+"--"+num);
                for (int i=1;i<=10;i++){
                    try {
                        Thread.sleep(1000);
                        Log.i("test","当前线程："+Thread.currentThread().getName()+"--"+i);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }else if("2".equals(num)){
                Log.i("test","当前线程："+Thread.currentThread().getName()+"--"+num);
                for(int i=10;i<=20;i++){
                    Log.i("test","当前线程："+Thread.currentThread().getName()+"--"+i);
                }

            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("test","注销服务");
    }
}